import { useMemo } from 'react';
import { PickColumns } from './Columns';
import { PresetField, PresetReturnType } from './interface';
import { getRowSelection } from './RowSelection';
import {
  BaseSourceGet,
  GetGovernmentPkg,
  GetGovernmentSource,
  GetPlatformPaper,
  GetPlatformPkg,
  ReadySourceGet,
} from './TableRequest';
/**
 * @desc 可供使用的预设的配置
 */
export function usePreset(preSetkey: PresetField, params: {}, columnsRender?: { tradeMap: Map<string, string> }) {
  return useMemo<PresetReturnType>(() => {
    if (preSetkey === '单选题选择') {
      return {
        title: '单选题选择',
        key: '单选题',
        props: {
          tableRequest: BaseSourceGet('100'),
          getColumns: PickColumns(['name', 'update']),
          searchFields: ['name'],
          getRowSelection: getRowSelection('多选'),
        },
      };
    }
    if (preSetkey === '多选题选择') {
      return {
        title: '多选题选择',
        key: '多选题',
        props: {
          tableRequest: BaseSourceGet('200'),
          getColumns: PickColumns(['name', 'update']),
          searchFields: ['name'],
          getRowSelection: getRowSelection('多选'),
        },
      };
    }
    if (preSetkey === '判断题选择') {
      return {
        title: '判断题选择',
        key: '判断题',
        props: {
          tableRequest: BaseSourceGet('300'),
          getColumns: PickColumns(['name', 'update']),
          searchFields: ['name'],
          getRowSelection: getRowSelection('多选'),
        },
      };
    }
    if (preSetkey === '课件') {
      return [
        {
          title: '视频',
          key: '视频',
          props: {
            tableRequest: BaseSourceGet('700'),
            getColumns: PickColumns(['name', 'update']),
            searchFields: ['name'],
            getRowSelection: getRowSelection('多选'),
          },
        },
        {
          title: '图文',
          key: '图文',
          props: {
            tableRequest: BaseSourceGet('800'),
            getColumns: PickColumns(['name', 'update']),
            searchFields: ['name'],
            getRowSelection: getRowSelection('多选'),
          },
        },
        {
          title: 'pdf',
          key: 'pdf',
          props: {
            tableRequest: BaseSourceGet('900'),
            getColumns: PickColumns(['name', 'update']),
            searchFields: ['name'],
            getRowSelection: getRowSelection('多选'),
          },
        },
        {
          title: '试卷',
          key: '试卷',
          props: {
            tableRequest: BaseSourceGet('600'),
            getColumns: PickColumns(['name', 'update']),
            searchFields: ['name'],
            getRowSelection: getRowSelection('多选'),
          },
        },
      ];
    }
    if (preSetkey === '已上架课件') {
      return [
        {
          title: '课件包',
          key: '课件包',
          props: {
            tableRequest: ReadySourceGet('课件包', params),
            getColumns: PickColumns(['name', 'isCharge', 'creat']),
            searchFields: ['name', 'classId'],
            getRowSelection: getRowSelection('单选'),
          },
          group: '1',
        },
        {
          title: '试卷',
          key: '试卷',
          props: {
            tableRequest: ReadySourceGet('试卷', params),
            getColumns: PickColumns(['name', 'isCharge', 'creat']),
            searchFields: ['name', 'classId'],
            getRowSelection: getRowSelection('多选'),
          },
          group: '2',
        },
      ];
    }
    if (preSetkey === '选择单个试卷') {
      return {
        title: '选择试卷',
        key: '选择单个试卷',
        props: {
          tableRequest: BaseSourceGet('600'),
          getColumns: PickColumns(['name']),
          searchFields: ['name'],
          getRowSelection: getRowSelection('单选'),
        },
      };
    }
    // 企业/协会学习计划
    if (preSetkey === '学习计划') {
      return [
        {
          title: '平台课件包',
          key: 'platform_coursewarePackage',
          props: {
            tableRequest: GetPlatformPkg(params),
            getColumns: PickColumns(['name', 'isCharge', 'trade', 'class', 'update'], columnsRender),
            searchFields: ['name', 'classId', 'trade'], //dateSort
            getRowSelection: getRowSelection('多选'),
          },
          group: '1',
        },
        {
          title: '平台试卷',
          key: 'platform_testPaper',
          props: {
            tableRequest: GetPlatformPaper(params),
            getColumns: PickColumns(['name', 'isCharge', 'trade', 'class', 'update'], columnsRender),
            searchFields: ['name', 'classId', 'trade'],
            getRowSelection: getRowSelection('多选'),
          },
          group: '2',
        },
        {
          title: '自建课件包',
          key: 'government_coursewarePackage',
          props: {
            tableRequest: GetGovernmentPkg(params),
            getColumns: PickColumns(['name', 'class', 'update']),
            searchFields: ['name', 'classId'],
            getRowSelection: getRowSelection('多选'),
          },
          group: '3',
        },
        {
          title: '自建课件',
          key: 'government_courseware',
          props: {
            tableRequest: GetGovernmentSource(params),
            getColumns: PickColumns(['name', 'update']),
            searchFields: ['name', 'coursewareGroup'],
            getRowSelection: getRowSelection('多选'),
          },
          group: '2',
        },
        {
          title: '自建试卷',
          key: 'government_testPaper',
          props: {
            tableRequest: GetGovernmentSource({ ...params, coursewareGroup: '600' }),
            getColumns: PickColumns(['name', 'update']),
            searchFields: ['name'],
            getRowSelection: getRowSelection('多选'),
          },
          group: '2',
        },
      ];
    }
    // 企业/协会考试计划
    if (preSetkey === '考试计划') {
      return [
        {
          title: '平台试卷',
          key: 'platform_testPaper',
          props: {
            tableRequest: GetPlatformPaper(params),
            getColumns: PickColumns(['name', 'isCharge', 'trade', 'class', 'update'], columnsRender),
            searchFields: ['name', 'classId', 'trade'],
            getRowSelection: getRowSelection('单选'),
          },
          group: '1',
        },
        {
          title: '自建试卷',
          key: 'government_testPaper',
          props: {
            tableRequest: GetGovernmentSource({ ...params, coursewareGroup: '600' }),
            getColumns: PickColumns(['name', 'update']),
            searchFields: ['name'],
            getRowSelection: getRowSelection('单选'),
          },
          group: '2',
        },
      ];
    }

    return {
      title: '未找到预设',
      key: '未知预设',
      props: {},
    };
  }, [preSetkey]);
}
